package java;

import java.util.Arrays;

public class Question27 {
    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        System.out.println(removeElement(nums,3));
    }
    public static int removeElement(int[] nums, int val) {
        if (nums == null || nums.length < 1) {
            return 0;
        }
        int count = 0;
        int left = 0;
        int right = nums.length - 1;
        while (left <= right){
            while (left <= right && nums[left] != val){
                left ++;
                count ++;
            }
            while (left <= right && nums[right] == val){
                right --;
            }
            if (left < right){
                nums[left ++] = nums[right --];
                count ++;
            }
        }
        return count;
    }
}
